home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / libsipp / transfor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-03  |  2.9 KB  |  162 lines

  1. /**
  2.  ** sipp - SImple Polygon Processor
  3.  **
  4.  **  A general 3d graphic package
  5.  **
  6.  **  Copyright Equivalent Software HB  1992
  7.  **
  8.  ** This program is free software; you can redistribute it and/or modify
  9.  ** it under the terms of the GNU General Public License as published by
  10.  ** the Free Software Foundation; either version 1, or any later version.
  11.  ** This program is distributed in the hope that it will be useful,
  12.  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ** GNU General Public License for more details.
  15.  ** You can receive a copy of the GNU General Public License from the
  16.  ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  **/
  18.  
  19. /** 
  20.  ** transforms.c - Functions that handles object transformations.
  21.  **/
  22.  
  23. #include <stdio.h>
  24.  
  25. #include <geometric.h>
  26. #include <sipp.h>
  27.  
  28.  
  29. /*
  30.  * Set the transformation matrix of OBJ to MATRIX.
  31.  */
  32. void
  33. object_set_transf(obj, matrix)
  34.     Object     *obj;
  35.     Transf_mat *matrix;
  36. {
  37.     MatCopy(&obj->transf, matrix);
  38. }
  39.  
  40.  
  41. /*
  42.  * Retrieve the transformation matrix of OBJ
  43.  */
  44. Transf_mat *
  45. object_get_transf(obj, matrix)
  46.     Object     *obj;
  47.     Transf_mat *matrix;
  48. {
  49.     Transf_mat *tmp;
  50.  
  51.     if (matrix != NULL) {
  52.         MatCopy(matrix, &obj->transf);
  53.         return matrix;
  54.     } else {
  55.         tmp = transf_mat_create(NULL);
  56.         MatCopy(tmp, &obj->transf);
  57.         return tmp;
  58.     }
  59. }
  60.  
  61.  
  62. /*
  63.  * Set the transformation matrix of OBJ to the identity matrix.
  64.  */
  65. void
  66. object_clear_transf(obj)
  67.     Object *obj;
  68. {
  69.     MatCopy(&obj->transf, &ident_matrix);
  70. }
  71.  
  72.  
  73. /*
  74.  * Post multiply MATRIX into the transformation matrix of OBJ.
  75.  */
  76. void
  77. object_transform(obj, matrix)
  78.     Object     *obj;
  79.     Transf_mat *matrix;
  80. {
  81.     mat_mul(&obj->transf, &obj->transf, matrix);
  82. }
  83.  
  84.  
  85. /*
  86.  * Rotate the object OBJ ANG radians about the x-axis.
  87.  */
  88. void
  89. object_rot_x(obj, ang)
  90.     Object *obj;
  91.     double  ang;
  92. {
  93.     mat_rotate_x(&obj->transf, ang);
  94. }
  95.  
  96.  
  97. /*
  98.  * Rotate the object OBJ ANG radians about the y-axis.
  99.  */
  100. void
  101. object_rot_y(obj, ang)
  102.     Object *obj;
  103.     double  ang;
  104. {
  105.     mat_rotate_y(&obj->transf, ang);
  106. }
  107.  
  108.  
  109. /*
  110.  * Rotate the object OBJ ANG radians about the z-axis.
  111.  */
  112. void
  113. object_rot_z(obj, ang)
  114.     Object *obj;
  115.     double  ang;
  116. {
  117.     mat_rotate_z(&obj->transf, ang);
  118. }
  119.  
  120.  
  121. /*
  122.  * Rotate the object OBJ ANG radians about the line defined
  123.  * by POINT and VEC.
  124.  */
  125. void
  126. object_rot(obj, point, vec, ang)
  127.     Object *obj;
  128.     Vector *point;
  129.     Vector *vec;
  130.     double  ang;
  131. {
  132.     mat_rotate(&obj->transf, point, vec, ang);
  133. }
  134.  
  135.  
  136. /*
  137.  * Scale the object OBJ with respect to the origin.
  138.  */
  139. void
  140. object_scale(obj, xscale, yscale, zscale)
  141.     Object *obj;
  142.     double  xscale, yscale, zscale;
  143. {
  144.     mat_scale(&obj->transf, xscale, yscale, zscale);
  145. }
  146.  
  147.  
  148. /*
  149.  * Translate the object OBJ.
  150.  */
  151. void
  152. object_move(obj, dx, dy, dz)
  153.     Object *obj;
  154.     double  dx, dy, dz;
  155. {
  156.     mat_translate(&obj->transf, dx, dy, dz);
  157. }
  158.  
  159.  
  160.  
  161.  
  162.